package so.wy.servicecenter.businessbed.manager.fm;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import so.wy.servicecenter.base.frame.manager.AbstractManager;
import so.wy.servicecenter.businessbed.dao.enums.StatusOrderEnum;
import so.wy.servicecenter.businessbed.dao.enums.StatusOrderPayEnum;
import so.wy.servicecenter.businessbed.dao.rdb.order.order.OrderDAO;
import so.wy.servicecenter.businessbed.dao.rdb.order.order.OrderDO;

import java.util.Collections;
import java.util.List;

@Service
@Scope("prototype")
public class OrderFManager extends AbstractManager {
    @Autowired
    private OrderDAO orderDAO;

    //获取设备正在进行中的订单
    public OrderDO getDeviceRunOrder(String deviceSerial) {
        return orderDAO.selectOne(new LambdaQueryWrapper<OrderDO>()
                .eq(OrderDO::getOrderStatus, StatusOrderEnum.PROCESSING.getCode())
                .eq(OrderDO::getDeviceSerial, deviceSerial));
    }

    //获取租户正在进行中的订单
    public OrderDO getRentUserRunOrder(Long rentUserId){
        return orderDAO.selectOne(new LambdaQueryWrapper<OrderDO>()
                .eq(OrderDO::getOrderStatus, StatusOrderEnum.PROCESSING.getCode())
                .eq(OrderDO::getRentUserId, rentUserId));
    }

    //获取租户未支付的订单
    public List<OrderDO> getRentUserNotPayOrder(Long rentUserId){
        return orderDAO.selectList(new LambdaQueryWrapper<OrderDO>()
                .notIn(OrderDO::getOrderStatus, Collections.singletonList(StatusOrderEnum.CLOSE.getCode()))
                .eq(OrderDO::getPayStatus, StatusOrderPayEnum.UNPAID.getCode())
                .eq(OrderDO::getRentUserId, rentUserId));
    }
}
